<?php
class M_giangvien extends CI_Model
{
    public $data;
    
	public function __construct()
	{
		parent::__construct();
		// Your own constructor code

	}
    public function insertmon($ten_mon, $nganh, $tinchi){
        $data = array();
        $data['ten_mon'] = $ten_mon;
        $data['nganh'] = $nganh;
        $data['tinchi'] = $tinchi;        
        if($this->db->insert('mon',$data)){
            return true;
        }else {
            return false;
        }
    }
    public function insertKhoahoc($ten, $noidung, $tl, $time, $mon, $giangvien, $nganh){
        $data = array();
        $data['ten_khoahoc'] = $ten;
        $data['noidung'] = $noidung;
        $data['thoi_luong'] = $tl;
        $data['time_start'] = $time;
        $data['id_mon'] = $mon;
        $data['giang_vien'] = $giangvien;
        $data['id_nganh'] = $nganh;
        if($this->db->insert('khoahoc',$data)){
            return true;
        }else {
            return false;
        }
    }
    public function insertBaigiang($tenbai, $noidung, $images, $video, $tailieu, $link, $ngay, $state, $idkhoahoc){
        $data = array();
        $data['ten_bai'] = $tenbai;
        $data['noidung'] = $noidung;
        $data['images'] = $images;
        $data['video'] = $video;
        $data['tailieu'] = $tailieu;
        $data['link'] = $link;
        $data['ngay'] = $ngay;
        $data['state'] = $state;
        $data['id_khoahoc'] = $idkhoahoc;
        
        if($this->db->insert('baigiang',$data)){
            return true;
        }else {
            return false;
        }
    }
        
    public function get_select()
    {     
        $this->db->select('*');
        $this->db->from('khoahoc');
        $result = $this->db->get();
        return $result;
        $result->free_result();
    }
    public function get_select_nganh()
    {     
        $this->db->select('*');
        $this->db->from('nganh');
        $result = $this->db->get();
        return $result;
        $result->free_result();
    }
     public function get_select_mon()
    {     
        $this->db->select('*');
        $this->db->from('mon');
        $result = $this->db->get();
        return $result;
        $result->free_result();
    }
    //Sử dụng cho ajax
    public function get_select_thoiluong($idkhoahoc){
        $this->db->select('*');
        $this->db->from('khoahoc');
        $this->db->where('id', $idkhoahoc);
        $result = $this->db->get();
        return $result;
        $result->free_result();
    }
    function get_delete($id) 
    {
        if(!empty($id)){
            $this->db->where('id', $id);
            $result = $this->db->delete('khoahoc');
            if($result){
                return true;
            }else{
                return false;
            }
        }
        return false;
    }
    public function get_update($id)
    {
        $data = array(
            'fullname'   =>$this->input->post('username'),
            'email'    =>$this->input->post('email'),
            'password'   =>sha1($this->input->post('password')),
            'state'   =>$this->input->post('state')
            ); 
        $this->db->where('id_user', $id);
        $this->db->update('login', $data);  
        return $result;
        $result->free_result();; 
    }
   
}
?>